﻿// NOTE: This comes from Peter Johansson at http://stackoverflow.com/questions/3670057/does-console-writeline-block

namespace MyCompany.Core {
	using System;
	using System.Collections.Concurrent;
	using System.Threading;

	public static class NonBlockingConsole {
		static readonly BlockingCollection<string> queuedTextToWrite = new BlockingCollection<string>();

		static NonBlockingConsole() {
			(new Thread(() => {
				while (true)
					Console.WriteLine(queuedTextToWrite.Take());
			}) { IsBackground = true /* Allows app to exit without thread exiting.*/ }).Start();
		}

		public static void WriteLine(string textToWrite) {
			queuedTextToWrite.Add(textToWrite);
		}
	}
}
